package com.rzico.sbl.ui.mine

import com.rzico.sbl.R
import com.rzico.sbl.databinding.ActivityFeedbackBinding
import com.rzico.sbl.model.BaseUrl
import com.rzico.sbl.viewmodel.CommonViewModel
import com.xinnuo.common.extend.get
import com.xinnuo.common.extend.oneClick
import com.xinnuo.common.extend.textTrim
import com.xinnuo.common_ui.base.BaseActivity

class FeedbackActivity : BaseActivity(R.layout.activity_feedback) {

    private val mBinding by lazy { ActivityFeedbackBinding.bind(getRootView()) }

    override fun getViewModel() = get<CommonViewModel>()

    override fun initData() {
        initTitle(title = "意见反馈")
    }

    override fun initListener() {
        mBinding
            .btSubmit
            .oneClick {
                if (mBinding
                        .feedbackInput
                        .textTrim
                        .isEmpty()
                ) {
                    showToast("请输入反馈内容")
                    return@oneClick
                }

                getViewModel()
                    .request(
                        requestUrl = BaseUrl.feedback,
                        isMultipart = true,
                        params = arrayOf(
                            "content" to mBinding.feedbackInput.textTrim
                        ),
                        onSuccess = {
                            showToast("信息提交成功！")
                            finishView()
                        }
                    )
            }
    }

}